home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBGRX100.ARJ / P8FILLP.C < prev    next >
Text File  |  1992-04-10  |  3KB  |  97 lines

  1. /** 
  2.  ** P8FILLP.C 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "p8.h"
  25. #include "memcopy.h"
  26. #include "bytedraw.h"
  27.  
  28. void _GrP8FillPattern(int x,int y,int width,GrPattern *p)
  29. {
  30.     pixptr dst;
  31.  
  32.     if(width <= 0) return;
  33.     x += CURC->gc_xoffset;
  34.     y += CURC->gc_yoffset;
  35.     dst = (pixptr)(CURC->gc_baseaddr + (y * CURC->gc_lineoffset) + x);
  36.     _ClrDir();
  37.     if(p->gp_ispixmap) {
  38.         int pattwdt = p->gp_pxp_width;
  39.         int optype  = C_OPER(p->gp_pxp_oper);
  40.         int cpysize = x % pattwdt;
  41.         pixptr srcline = (pixptr)(p->gp_pxp_source.gc_baseaddr +
  42.          ((y % p->gp_pxp_height) * p->gp_pxp_source.gc_lineoffset));
  43.         pixptr srcptr = srcline + cpysize;
  44.  
  45.         cpysize = pattwdt - cpysize;
  46.         _SaveDS();
  47.         while(width > 0) {
  48.         if(cpysize > width) cpysize = width;
  49.         switch(optype) {
  50.             case C_XOR: _RowCpyXorB(X,dst,srcptr,cpysize); break;
  51.             case C_OR:  _RowCpyOrB(O,dst,srcptr,cpysize);  break;
  52.             case C_AND: _RowCpyAndB(A,dst,srcptr,cpysize); break;
  53.             default:    _RowCpyB(C,dst,srcptr,cpysize);       break;
  54.         }
  55.         width  -= cpysize;
  56.         dst    += cpysize;
  57.         srcptr  = srcline;
  58.         cpysize = pattwdt;
  59.         }
  60.         _RestoreDS();
  61.     }
  62.     else {
  63.         int bits = p->gp_bmp_data[y % p->gp_bmp_height];
  64.         int fgc  = p->gp_bmp_fgcolor;
  65.         int bgc  = p->gp_bmp_bgcolor;
  66.         int fgop = C_OPER(fgc);
  67.         int bgop = C_OPER(bgc);
  68.         int drawfg = _GrP8DrawTable[fgop] ^ (fgc &= C_SIGNIF);
  69.         int drawbg = _GrP8DrawTable[bgop] ^ (bgc &= C_SIGNIF);
  70.  
  71.         x &= 7;
  72.         bits = (bits << x) | ((bits & 0xff) >> (8 - x));
  73.         if(drawfg && drawbg && (fgop == bgop)) {
  74.         bgc |= ((fgc ^ bgc) << 8);
  75.         switch(fgop) {
  76.             case C_XOR: _PatternXor(dst,bits,width,bgc); return;
  77.             case C_OR:  _PatternOr(dst,bits,width,bgc);  return;
  78.             case C_AND: _PatternAnd(dst,bits,width,bgc); return;
  79.             default:    _PatternSet(dst,bits,width,bgc); return;
  80.         }
  81.         }
  82.         if(drawfg) switch(fgop) {
  83.         case C_XOR: _PattFGCXor(dst,bits,width,fgc); break;
  84.         case C_OR:  _PattFGCOr(dst,bits,width,fgc);  break;
  85.         case C_AND: _PattFGCAnd(dst,bits,width,fgc); break;
  86.         default:    _PattFGCSet(dst,bits,width,fgc); break;
  87.         }
  88.         if(drawbg) switch(bgop) {
  89.         case C_XOR: _PattBGCXor(dst,bits,width,bgc); break;
  90.         case C_OR:  _PattBGCOr(dst,bits,width,bgc);  break;
  91.         case C_AND: _PattBGCAnd(dst,bits,width,bgc); break;
  92.         default:    _PattBGCSet(dst,bits,width,bgc); break;
  93.         }
  94.     }
  95. }
  96.  
  97.